<?php

namespace App\Rules;

use App\Models\TradeQueue;
use Illuminate\Contracts\Validation\Rule;

class MoreTime implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $nowTime = strtotime(date('Y-m-d H:i:s'));
        $user = auth('api')->user();
        $isQueue = $user->tradeQueues->OrderBy('id','desc')->first();
        if($isQueue) {
            $created_at = $isQueue->created_at;
        }else {
            return true;
        }
        switch ($value) {
            case 'deposit':
                if($nowTime - $created_at > 24*60*60) {
                    return false;
                }
                return true;
            case 'withdraw':
                return true;
            default:
                return false;
        }
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The validation error message.';
    }
}
